/**
 * Created by zhouwenbo on 2017/5/11.
 */
function loadharbordata() {
  var str1 = "";
  var summarydata = JSON.parse(storage.kubersummary);
  var hotdata = JSON.parse(storage.kuberhot);
  for (var item in summarydata) {
    str1 += ' <div class="col-md-12 margin-css"><span>' + item + ':</span><span>' + summarydata[item] + '</span></div>';
  }
  $("#harborsummary").append(str1);
  str1 = "";
  for (var i = 0; i < hotdata.length; i++) {
    str1 += '  <div class="col-md-12 margin-css" style="border-bottom: 1px solid #999;padding: 10px 0;"><div class="col-md-6">' + hotdata[i].name + '</div><div class="col-md-6">' + hotdata[i].count + '</div></div>';

  }
  $("#harborhot").append(str1);
}
function loadhostdata() {
  $(".host-container").empty();
  var hostdata = JSON.parse(storage.kuberhosts);
  var poddata = JSON.parse(storage.kuberpods)
  var str1 = ""
  var arrlisthost = new Array();
  var isfind = false;
  var obj = new Object();
  var location = 0;
  for (var j = 0; j < poddata.length; j++) {

    for (var k = 0; k < arrlisthost.length; k++) {
      if (poddata[j].hostIP == arrlisthost[k].hostIP) {
        location = k;
        isfind = true;
        break;
      }

    }
    if (isfind) {
      isfind = false;
      arrlisthost[location].contains.push(poddata[j]);
    } else {
      var obj = new Object();
      obj.hostIP = poddata[j].hostIP
      obj.contains = new Array();
      obj.contains.push(poddata[j]);

      arrlisthost.push(obj)
    }

  }
  isfind = false;
  for (var i = 0; i < arrlisthost.length; i++) {
    arrlisthost[i].envirs = new Array();
    for (var j = 0; j < arrlisthost[i].contains.length; j++) {

      for (var k = 0; k < arrlisthost[i].envirs.length; k++) {
        if (arrlisthost[i].contains[j].namespace = arrlisthost[i].envirs[k].namespace) {
          isfind = true;
          location = k
        }
      }
      if (isfind) {
        arrlisthost[i].envirs[location].contains.push(arrlisthost[i].contains[j]);
        isfind = false;
      }
      else {
        var obj = new Object();
        obj.namespace = arrlisthost[i].contains[j].namespace;
        obj.contains = new Array();
        obj.contains.push(arrlisthost[i].contains[j]);
        arrlisthost[i].envirs.push(obj);

      }
    }
  }
  for (var i = 0; i < hostdata.length; i++) {
    str1 += '<div class="col-md-4" style="border: 4px solid #999;padding: 10px;"><div class="col-md-12"><div style="text-align: left;"><span>Active status</span></div><div style="text-align: center;"><span>' + hostdata[i].name + '</span></div><div style="padding: 0 20px;"><span>' + hostdata[i].hostip + '</span><span style="margin-left: 38%;">' + hostdata[i].kubeletVersion + '</span></div><div style="text-align: center;"><span>' + hostdata[i].osImage + '</span></div><div class="col-md-12" style="padding: 0;"><div class="col-md-4"><span>' + hostdata[i].cpu + '</span></div><div class="col-md-4"><span>' + hostdata[i].memory + '</span></div><div class="col-md-4"><span>' + hostdata[i].disk + '</span></div></div></div>';
    for (var h = 0; h < arrlisthost.length; h++) {
      if (arrlisthost[h].hostIP == hostdata[i].hostip) {
        for (var k = 0; k < arrlisthost[h].envirs.length; k++) {
          str1 += '   <div class="col-md-12" style="margin-top: 20px;"><div class="col-md-12" style="padding: 10px;background-color: #999;">' + arrlisthost[h].envirs[k].namespace + '</div>'

          for (var s = 0; s < arrlisthost[h].envirs[k].contains.length; s++) {
            str1 += '<div class="col-md-12" style="padding: 10px;border: 1px #999 solid;">';
            str1 += '<span>' + arrlisthost[h].envirs[k].contains[s].status + '</span><span>' + arrlisthost[h].envirs[k].contains[s].name + '</span><span>' + arrlisthost[h].envirs[k].contains[s].podIP + '</span>'
            str1 += ' </div>';
          }
          str1 += ' </div>';
        }
      }
    }
    str1 += '</div>';
  }
  $(".host-container").append(str1);
}
function datastart() {
  var res = '{  "my_project_count": 4,  "my_repo_count": 8,  "public_project_count": 4,  "public_repo_count": 8}'
  var storage = window.localStorage;
  storage.kubersummary = res;
  res = '[{"name":"jenkins/jenkins_2.19.3","count": 7},{"name": "library/maven","count": 7}, {"name":"library/debian","count": 3},{"name": "library/hello-world","count": 2},{"name": "library/abh1nav_dockerui","count": 0}]'
  storage.kuberhot = res;
  res = '{"Data":[{"name":"aaa","uid":"b7bea9b6-352e-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-05-10T03:14:02Z","status":"Active","resourceVersion":"7075430"},{"name":"aaasadasd","uid":"fc63c1c6-3613-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-05-11T06:35:12Z","status":"Active","resourceVersion":"7199807"},{"name":"asdasdsadasd","uid":"9484c6b1-360f-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-05-11T06:03:40Z","status":"Active","resourceVersion":"7197388"},{"name":"asddddd","uid":"fec55f7b-3613-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-05-11T06:35:16Z","status":"Active","resourceVersion":"7199814"},{"name":"dddddddd","uid":"006822a3-3614-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-05-11T06:35:19Z","status":"Active","resourceVersion":"7199818"},{"name":"default","uid":"615c19d1-ffe5-11e6-9793-000c29b7a2dd","creationTimestamp":"2017-03-03T07:45:32Z","status":"Active","resourceVersion":"6"},{"name":"gghh","uid":"4d5858bb-348a-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-05-09T07:37:06Z","status":"Active","resourceVersion":"6985723"},{"name":"haha","uid":"f8f128a3-2983-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-04-25T06:54:05Z","status":"Active","resourceVersion":"5456485"},{"name":"kube-system","uid":"615e60ef-ffe5-11e6-9793-000c29b7a2dd","creationTimestamp":"2017-03-03T07:45:32Z","status":"Active","resourceVersion":"9"},{"name":"wwww","uid":"8d1f5f06-352d-11e7-a5cf-000c29b7a2dd","creationTimestamp":"2017-05-10T03:05:41Z","status":"Active","resourceVersion":"7074762"}],"AllRows":10,"Success":true}'
  storage.kuberenvir = res;
  res = '[{"maxCPU":5,"maxMenory":500,"nodePort":30004,"method":"get","namespace":"default","podIP":"172.17.12.2","hostIP":"10.142.20.208","containerPort":8080,"status":"Running","name":"jenkins-xbr2w","hostname":"10.142.20.208","image":"jenkins:2.46.2","uid":"fd3ec7eb-316b-11e7-a5cf-000c29b7a2dd"},{"maxCPU":5,"maxMenory":500,"nodePort":30005,"method":"get","namespace":"default","podIP":"172.17.12.4","hostIP":"10.142.20.208","containerPort":6379,"status":"Stopped","name":"redis-master-1m1w8","hostname":"10.142.20.208","image":"kubeguide/redis-master","uid":"ee81281a-2665-11e7-a5cf-000c29b7a2dd"},{"maxCPU":5,"maxMenory":500,"nodePort":30006,"method":"get","namespace":"default","podIP":"172.17.95.8","hostIP":"10.142.20.207","containerPort":6379,"status":"Running","name":"redis-master-z4jms","hostname":"10.142.20.207","image":"kubeguide/redis-master","uid":"fd402beb-316b-11e7-a5cf-000c29b7a2dd"},{"maxCPU":5,"maxMenory":500,"nodePort":30007,"method":"get","namespace":"default","podIP":"172.17.12.6","hostIP":"10.142.20.208","containerPort":6379,"status":"Running","name":"redis-slave-1g4m3","hostname":"10.142.20.208","image":"kubeguide/guestbook-redis-slave","uid":"bfadc0b6-361f-11e7-b659-000c29b7a2dd"},{"maxCPU":5,"maxMenory":500,"nodePort":30008,"method":"get","namespace":"default","podIP":"172.17.12.3","hostIP":"10.142.20.208","containerPort":6379,"status":"Running","name":"redis-slave-41jnl","hostname":"10.142.20.208","image":"kubeguide/guestbook-redis-slave","uid":"fd425134-316b-11e7-a5cf-000c29b7a2dd"}]';
  storage.kuberpods = res;
  res = '[{"name":"10.142.20.208","hostip":"10.142.20.208","disk":"50GB","cpu":16,"memory":"16251856Ki","osImage":"CentOS Linux 7 (Core)","kernelVersion":"3.10.0-514.6.2.el7.x86_64","kubeletVersion":"v1.5.2"},{"name":"10.142.20.207","hostip":"10.142.20.207","disk":"50GB","cpu":16,"memory":"16251856Ki","osImage":"CentOS Linux 7 (Core)","kernelVersion":"3.10.0-514.6.2.el7.x86_64","kubeletVersion":"v1.5.2"}]';
  storage.kuberhosts = res;
}
var storage = window.localStorage;
// this is open menu click
// 这是header的focus事件
function menuStack() {
  $('.ui.stackable.menu')
    .on('click', '.item', function () {
      $(this)
        .addClass('active')
        .siblings('.item')
        .removeClass('active');
    });
}
// 这是sidebar的focus事件
function siderStack() {
  $('.accordion')
    .on('click', '.item', function () {
      $(this)
        .addClass('open')
        .siblings('.item')
        .removeClass('open');
    });
}

// this is resoures sidebar
// 这是侧边栏siderbar
$(function () {
  datastart();
  var Accordion = function (el, multiple) {
    this.el = el || {};
    this.multiple = multiple || false;

    // Variables privadas
    var links = this.el.find('.link');
    // Evento
    links.on('click', { el: this.el, multiple: this.multiple }, this.dropdown)
  }

  Accordion.prototype.dropdown = function (e) {
    var $el = e.data.el;
    $this = $(this),
      $next = $this.next();

    $next.slideToggle();
    $this.parent().toggleClass('open');

    if (!e.data.multiple) {
      $el.find('.submenu').not($next).slideUp().parent().removeClass('open');
    }
    ;
  }

  var accordion = new Accordion($('#accordion'), false);
});
// this is controller openMenu
// this can be optimize
// 这里控制五个模块的显隐藏性，有优化空间
function openTimeJudge() {
  $('.time-judge').removeClass('hidden');
  $('.manage-resources').addClass('hidden');
  $('.project-select').addClass('hidden');
  $('.work-flow').addClass('hidden');
  $('.data-show').addClass('hidden');
  $('.product-list').addClass('hidden');
}

function openManageResources() {
  $('.time-judge').addClass('hidden');
  $('.manage-resources').removeClass('hidden');
  $('.project-select').addClass('hidden');
  $('.work-flow').addClass('hidden');
  $('.data-show').addClass('hidden');
  $('.product-list').addClass('hidden');
}

function openProjectSelect() {
  $('.time-judge').addClass('hidden');
  $('.manage-resources').addClass('hidden');
  $('.project-select').removeClass('hidden');
  $('.work-flow').addClass('hidden');
  $('.data-show').addClass('hidden');
  $('.product-list').addClass('hidden');
}

function openWorkFlow() {
  $('.time-judge').addClass('hidden');
  $('.manage-resources').addClass('hidden');
  $('.project-select').addClass('hidden');
  $('.work-flow').removeClass('hidden');
  $('.data-show').addClass('hidden');
  $('.product-list').addClass('hidden');
}

function openDataShow() {
  $('.time-judge').addClass('hidden');
  $('.manage-resources').addClass('hidden');
  $('.project-select').addClass('hidden');
  $('.work-flow').addClass('hidden');
  $('.data-show').removeClass('hidden');
  $('.product-list').addClass('hidden');
}

function openProductList() {
  $('.time-judge').addClass('hidden');
  $('.manage-resources').addClass('hidden');
  $('.project-select').addClass('hidden');
  $('.work-flow').addClass('hidden');
  $('.data-show').addClass('hidden');
  $('.product-list').removeClass('hidden');
}

//产品展示页面静态数据(created by yanglei)
var bdfProductList = [
  {
    "id": "59150fa93162b31c7434ab17",
    "product_name": "YQ",
    "product_version": "V1.1.0/V1.1.1/V1.1.2/V1.2.0",
    "product_latest_update_time": "17-04-10 09:02:51",
    "watchedBies": [
      {
        "role": "FORMAL_DEV",
        "picName": "张工",
        "picPhone": "18812387635"
      },
      {
        "role": "ASSISTANT_DEV",
        "picName": "李工",
        "picPhone": "18812337635"
      },
      {
        "role": "FORMAL_TEST",
        "picName": "杨工",
        "picPhone": "18812387645"
      },
      {
        "role": "ASSISTANT_TEST",
        "picName": "王工",
        "picPhone": "18812347635"
      }
    ],
    "tarFileList": [{
      "id": 1377,
      "fileName": "build.zip",
      "version": "",
      "type": "zip",
      "size": 279900,
      "date": "Apr 01 16:13:56 CST 2017",
      "permission": "null",
      "parent": "/data/toolTest/BC-LogManager/Stable/V1.1.2",
      "productVersion": "V1.1.2",
      "projectList": null
    }, {
      "id": 15,
      "fileName": "elasticsearch-1.2.0.tar",
      "version": "",
      "type": "tar",
      "size": 71116800,
      "date": "Apr 10 09:02:51 CST 2017",
      "permission": "-rw-r--r--",
      "parent": "/BC-LogManager/Stable/V1.1.1",
      "productVersion": "V1.2.0",
      "projectList": null
    }, {
      "id": 14,
      "fileName": "BC-Logmanager-web_1.1.1.tar.gz",
      "version": "",
      "type": "gz",
      "size": 43607866,
      "date": "Jan 29 09:22:50 CST 2017",
      "permission": "-rw-r--r--",
      "parent": "/BC-LogManager/Stable/V1.1.1",
      "productVersion": "V1.1.1",
      "projectList": null
    }, {
      "id": 13,
      "fileName": "BC-Logmanager-server_1.1.0.tar.gz",
      "version": "",
      "type": "gz",
      "size": 122420762,
      "date": "Jan 18 10:21:45 CST 2017",
      "permission": "-rw-r--r--",
      "parent": "/BC-LogManager/Stable/V1.1.1",
      "productVersion": "V1.1.0",
      "projectList": null
    }]
  },
  {
    "id": "59150fa93162b31c7434ab18",
    "product_name": "Crossdata",
    "product_version": "V1.4.8",
    "product_latest_update_time": "17-04-27 16:46:31",
    "watchedBies": [
      {
        "role": "FORMAL_DEV",
        "picName": "张福",
        "picPhone": "18842287635"
      },
      {
        "role": "ASSISTANT_DEV",
        "picName": "李云川",
        "picPhone": "18817337635"
      },
      {
        "role": "FORMAL_TEST",
        "picName": "杨福星",
        "picPhone": "18812337612"
      },
      {
        "role": "ASSISTANT_TEST",
        "picName": "王伏龙",
        "picPhone": "18819341635"
      }
    ],
    "tarFileList": [{
      "id": 1946,
      "fileName": "crossdataV1.4.8.tar.gz",
      "version": "",
      "type": "gz",
      "size": 175793528,
      "date": "Apr 27 16:46:31 CST 2017",
      "permission": "crossdata01",
      "parent": "/CrossData/Stable/V1.4.8",
      "productVersion": "V1.4.8",
      "projectList": null
    }, {
      "id": 987,
      "fileName": "crossdataV1.4.7.tar.gz",
      "version": "",
      "type": "gz",
      "size": 175682636,
      "date": "Feb 23 19:39:24 CST 2017",
      "permission": "crossdata01",
      "parent": "/CrossData/Stable/V1.4.7",
      "productVersion": "V1.4.7",
      "projectList": null
    }, {
      "id": 158,
      "fileName": "crossdataV1.4.6.tar.gz",
      "version": "",
      "type": "gz",
      "size": 175643486,
      "date": "Jan 23 11:31:09 CST 2017",
      "permission": "-rw-rw-r--",
      "parent": "/CrossData/Stable/V1.4.6",
      "productVersion": "V1.4.6",
      "projectList": null
    }, {
      "id": 156,
      "fileName": "crossdataV1.4.5.tar.gz",
      "version": "",
      "type": "gz",
      "size": 176339257,
      "date": "Dec 27 16:33:29 CST 2016",
      "permission": "-rw-rw-r--",
      "parent": "/CrossData/Stable/V1.4.5",
      "productVersion": "V1.4.5",
      "projectList": null
    }, {
      "id": 154,
      "fileName": "crossdataV1.4.4.tar.gz",
      "version": "",
      "type": "gz",
      "size": 166532741,
      "date": "Dec 16 09:31:21 CST 2016",
      "permission": "-rw-r--r--",
      "parent": "/CrossData/Stable/V1.4.4",
      "productVersion": "V1.4.4",
      "projectList": null
    }, {
      "id": 150,
      "fileName": "crossdata-1.4.2-SNAPSHOT.jar",
      "version": "",
      "type": "jar",
      "size": 2751216,
      "date": "Nov 20 13:25:49 CST 2016",
      "permission": "-rw-r--r--",
      "parent": "/CrossData/Stable/V1.4.2",
      "productVersion": "V1.4.2",
      "projectList": null
    }, {
      "id": 148,
      "fileName": "crossdata-1.4.0-SNAPSHOT.jar",
      "version": "",
      "type": "jar",
      "size": 2749136,
      "date": "Nov 08 17:12:49 CST 2016",
      "permission": "-rw-r--r--",
      "parent": "/CrossData/Stable/V1.4.0",
      "productVersion": "V1.4.0",
      "projectList": null
    }, {
      "id": 146,
      "fileName": "crossdata-1.0.0-SNAPSHOT.jar",
      "version": "",
      "type": "jar",
      "size": 2581645,
      "date": "Oct 25 10:37:49 CST 2016",
      "permission": "-rw-r--r--",
      "parent": "/CrossData/Stable/V1.0.0",
      "productVersion": "V1.0.0",
      "projectList": null
    }, {
      "id": 145,
      "fileName": "crossdata-1.2.0-SNAPSHOT.jar",
      "version": "",
      "type": "jar",
      "size": 2705150,
      "date": "Oct 12 14:12:49 CST 2016",
      "permission": "-rw-r--r--",
      "parent": "/CrossData/Stable/V1.2.0",
      "productVersion": "V1.2.0",
      "projectList": null
    }, {
      "id": 144,
      "fileName": "crossdata-0.6-005-SNAPSHOT.jar",
      "version": "",
      "type": "jar",
      "size": 2319284,
      "date": "Sep 24 10:34:12 CST 2016",
      "permission": "-rw-r--r--",
      "parent": "/CrossData/Stable/V0.6.0",
      "productVersion": "V0.6.0",
      "projectList": null
    }, {
      "id": 143,
      "fileName": "crossdata-0.8.0-SNAPSHOT.jar",
      "version": "",
      "type": "jar",
      "size": 2358996,
      "date": "Sep 16 12:30:36 CST 2016",
      "permission": "-rw-r--r--",
      "parent": "/CrossData/Stable/V0.8.0",
      "productVersion": "V0.8.0",
      "projectList": null
    }]
  },
  {
    "id": "59150fa93162b31c7434ab1a",
    "product_name": "TBD",
    "product_version": "V5.1",
    "product_latest_update_time": "17-05-08 19:39:24",
    "watchedBies": [
      {
        "role": "FORMAL_DEV",
        "picName": "李华",
        "picPhone": "18812387635"
      },
      {
        "role": "ASSISTANT_DEV",
        "picName": "孙雯雯",
        "picPhone": "12812317635"
      },
      {
        "role": "FORMAL_TEST",
        "picName": "王子文",
        "picPhone": "16812388645"
      },
      {
        "role": "ASSISTANT_TEST",
        "picName": "罗文",
        "picPhone": "18816348635"
      }
    ],
    "tarFileList": [
      {
        "id": 111,
        "fileName": "TBD.4.1.tar.gz",
        "version": "",
        "type": "gz",
        "size": 175793528,
        "date": "Apr 12 16:46:31 CST 2017",
        "permission": "crossdata01",
        "parent": "/CrossData/Stable/V1.4.8",
        "productVersion": "V4.1",
        "projectList": null
      }, {
        "id": 987,
        "fileName": "TBD.5.1.tar.gz",
        "version": "",
        "type": "gz",
        "size": 175682636,
        "date": "May 08 19:39:24 CST 2017",
        "permission": "crossdata01",
        "parent": "/CrossData/Stable/V1.4.7",
        "productVersion": "V5.1",
        "projectList": null
      }
    ]
  },
  {
    "id": "59150fa93162b31c7434ab1e",
    "product_name": "HugeTable",
    "product_version": "V1.1.0",
    "product_latest_update_time": "17-04-12 18:26:12",
    "watchedBies": [
      {
        "role": "FORMAL_DEV",
        "picName": "韩则龙",
        "picPhone": "18819357635"
      },
      {
        "role": "ASSISTANT_DEV",
        "picName": "朱文藏",
        "picPhone": "18812937235"
      },
      {
        "role": "FORMAL_TEST",
        "picName": "张晓宇",
        "picPhone": "18212389645"
      },
      {
        "role": "ASSISTANT_TEST",
        "picName": "杨远雄",
        "picPhone": "18812327635"
      }
    ],
    "tarFileList": [{
      "id": 04,
      "fileName": "HT-1.1.0.tar.gz",
      "version": "",
      "type": "gz",
      "size": 175793528,
      "date": "Apr 12 18:26:12 CST 2017",
      "permission": "HugeTable",
      "parent": "/CrossData/Stable/V1.4.8",
      "productVersion": "V1.1.0",
      "projectList": null
    }]
  },
  {
    "id": "59150fa93162b31c7434ab31",
    "product_name": "ZhiLiao",
    "product_version": "-",
    "product_latest_update_time": "-",
    "watchedBies": [
      {
        "role": "FORMAL_DEV",
        "picName": "陈银",
        "picPhone": "18812783635"
      },
      {
        "role": "ASSISTANT_DEV",
        "picName": "李元",
        "picPhone": "18832357635"
      },
      {
        "role": "FORMAL_TEST",
        "picName": "王书其",
        "picPhone": "18814386645"
      },
      {
        "role": "ASSISTANT_TEST",
        "picName": "李云",
        "picPhone": "18823457635"
      }
    ],
    "tarFileList": []
  }
];
function saveBdfProductList() {
  localStorage.setItem('bdfProductList', JSON.stringify(bdfProductList));
};

//初步加载页面
window.onload = function () {
  openManageResources();
  openEnvi();
  siderStack();
  menuStack();
  initTable();
  saveBdfProductList();

  //粒子效果
  var config = {
    vx: 4,//点x轴速度,正为右，负为左
    vy: 4,//点y轴速度
    height: 2,//点高宽，其实为正方形，所以不宜太大
    width: 2,
    count: 100,//点个数
    color: "121, 162, 185",//点颜色
    stroke: "130,255,255",//线条颜色
    dist: 6000,//点吸附距离
    e_dist: 20000,//鼠标吸附加速距离
    max_conn: 10//点到点最大连接数
  }
  //调用
  CanvasParticle(config);

  // //kubernames_add init
  // var oldname = GetQueryString("name");
  // if (oldname != null) {
  //   $("#name").val(oldname);
  // }
};

// this is manageResoruces mock data
// http://www.datatables.club/manual/#data
// 这里是manage resources 的数据，写死到页面内，需要实现localstorage，应用了jq的datatables

var containerData = [
  {
    "status": "aaa",
    "name": "b7bea9b6-352e-11e7-a5cf-000c29b7a2dd",
    "ipAddress": "2017-05-10T03:14:02Z",
    "host": "Active",
    "image": "7075430",
    "controller": "222222"
  },
  {
    "status": "aaa",
    "name": "b7bea9b6-352e-11e7-a5cf-000c29b7a2dd",
    "ipAddress": "2017-05-10T03:14:02Z",
    "host": "Active",
    "image": "7075430",
    "controller": "222222"
  },
  {
    "status": "aaa",
    "name": "b7bea9b6-352e-11e7-a5cf-000c29b7a2dd",
    "ipAddress": "2017-05-10T03:14:02Z",
    "host": "Active",
    "image": "7075430",
    "controller": "222222"
  },
  {
    "status": "aaa",
    "name": "b7bea9b6-352e-11e7-a5cf-000c29b7a2dd",
    "ipAddress": "2017-05-10T03:14:02Z",
    "host": "Active",
    "image": "7075430",
    "controller": "222222"
  },
  {
    "status": "aaa",
    "name": "b7bea9b6-352e-11e7-a5cf-000c29b7a2dd",
    "ipAddress": "2017-05-10T03:14:02Z",
    "host": "Active",
    "image": "7075430",
    "controller": "222222"
  },
  {
    "status": "aaa",
    "name": "b7bea9b6-352e-11e7-a5cf-000c29b7a2dd",
    "ipAddress": "2017-05-10T03:14:02Z",
    "host": "Active",
    "image": "7075430",
    "controller": "222222"
  }
];
function Envirs(name, uid, creationTimestamp, status, resourceVersion) {
  this.name = name;
  this.uid = uid;
  this.creationTimestamp = creationTimestamp;
  this.status = status;
  this.resourceVersion = resourceVersion;
  this.action = function () {

    var str1 = "<button class=\"btn btn-primary btn-xs\" onclick=\"editnamespace('" + a1.Data[i].name + "')\" title=\"编辑\" >编辑</button>&nbsp;&nbsp;";
    str1 += "<button class=\"btn btn-primary btn-xs\" onclick=\"deletenamespace('" + a1.Data[i].name + "','" + a1.Data[i].uid + "')\" title=\"删除\" >删除</button>&nbsp;&nbsp;";

    return str1;
  }
}
// function showinfo() {
//     $.modalz("/src/app/views/kuber_namespaceadd.html", "新增");
// }
// 这里是jq的datatables加载数据
$(document).ready(function () {
  // $("#btnadd").click(function () {
  //     showinfo();
  // })
  var storage = window.localStorage;
  var data = JSON.parse(storage.kuberenvir);
  $('#table_id_example').DataTable({
    data: JSON.parse(storage.kuberenvir),
    language: {
      "sProcessing": "处理中...",
      "sLengthMenu": "显示 _MENU_ 项结果",
      "sZeroRecords": "没有匹配结果",
      "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
      "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
      "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
      "sInfoPostFix": "",
      "sSearch": "搜索:",
      "sUrl": "",
      "sEmptyTable": "表中数据为空",
      "sLoadingRecords": "载入中...",
      "sInfoThousands": ",",
      "oPaginate": {
        "sFirst": "首页",
        "sPrevious": "上页",
        "sNext": "下页",
        "sLast": "末页"
      },
      "oAria": {
        "sSortAscending": ": 以升序排列此列",
        "sSortDescending": ": 以降序排列此列"
      }
    },
    columns: [
      { data: 'name' },
      { data: 'uid' },
      { data: 'creationTimestamp' },
      { data: 'status' },
      { data: 'resourceVersion' }
    ]

  });
});
function showenvir(uid, name) {
  window.location.href = "kuber_envir.html?envirId=" + uid + "&namespace=" + name;
}
function initTable() {
  var enviData = JSON.parse(storage.kuberenvir).Data;

  //初始化环境table
  $('#etlInfo').bootstrapTable({
    data: enviData,
    striped: true,
    cache: false,
    pagination: true,
    sidePagination: 'client',
    pageNumber: 1,
    pageSize: 10,
    uniqueId: true,
    cardView: false,
    columns: [
      {
        field: 'name',
        title: '名称',
        formatter: function (value, row, index) {
          return '<a href="#" mce_href="#" onclick="showenvir(\'' + row.uid + '\',\'' + row.name + '\')">' + row.name + '</a> ';
        }
      }, {
        field: 'uid',
        title: '唯一ID',
        sortable: true
      }, {
        field: 'creationTimestamp',
        title: '创建时间',
        sortable: true
      }, {
        field: 'status',
        title: '状态',
        sortable: true
      }, {
        field: 'resourceVersion',
        title: '版本号'
      }, {
        field: 'dsad',
        title: '操作',
        events: operateEvents,
        formatter: operateFormatter
      }]
  });
  //初始化容器table
  var poddata1 = JSON.parse(storage.kuberpods);
    $('#containerInfo').bootstrapTable({
        data:poddata1,
        striped: true,
        cache: false,
        pagination: true,
        sidePagination:'client',
        pageNumber: 1,
        pageSize: 10,
        uniqueId: true,
        cardView: false,
        columns: [
            {
                field: 'status',
                title: '状态',
                sortable: true
            }, {
                field: 'name',
                title: '名称',
                sortable: true
            }, {
                field: 'podIP',
                title: 'ip地址',
                sortable: true
            }, {
                field: 'hostIP',
                title: '主机',
                sortable: true
            }, {
                field: 'image',
                title: '镜像',
                sortable: true
            }]
    });
}

function operateFormatter() {
  return [
    '<a class="edit " href="javascript:void(0)" title="Edit">',
    '编辑',
    '</a>',
    '<a class="delete" style="margin-left: 16px;" href="javascript:void(0)" title="Delete">',
    '删除',
    '</a>'
    ,
  ].join('');
}
window.operateEvents = {
  'click .delete': function (e, value, row, index) {
    deletenamespace(row.name, row.uid);
  },
  'click .edit': function (e, value, row, index) {
    editnamespace(row.name);
  }
};
function editnamespace(name) {
  $('#btnadd').modal('show');
  checkSelectItems(name);
  // $.modalz("/src/app/views/kuber_namespaceadd.html?name=" + name, "编辑", 250, 120);
}
function deletenamespace(name, uid) {
  var storage = window.localStorage;
  var a1 = storage.kuberenvir;
  a1 = JSON.parse(a1);
  for (var i = 0; i < a1.Data.length; i++) {
    if (a1.Data[i].name == name) {
      a1.Data.splice(i, 1);
    }
  }
  storage.kuberenvir = JSON.stringify(a1);
  timedloadenvir();

}
function timedloadenvir() {
  $('#etlInfo').bootstrapTable('destroy');
  setTimeout("initTable()", 200);

}

// 这里manage-rources侧边栏和右边container显隐藏控制
function openEnvi() {
  $('.envi-li').addClass('open');
  $('.envi-table').removeClass('hidden');
  $('.host-page').addClass('hidden');
  $('.container-page').addClass('hidden');
  $('.image-page').addClass('hidden');
}

function openHost() {
  $('.envi-table').addClass('hidden');
  $('.host-page').removeClass('hidden');
  $('.container-page').addClass('hidden');
  $('.image-page').addClass('hidden');
  loadhostdata();
}

function openContainer() {
  $('.envi-table').addClass('hidden');
  $('.host-page').addClass('hidden');
  $('.container-page').removeClass('hidden');
  $('.image-page').addClass('hidden');
}

function openImage() {
  $('.envi-table').addClass('hidden');
  $('.host-page').addClass('hidden');
  $('.container-page').addClass('hidden');
  $('.image-page').removeClass('hidden');
  loadharbordata();
}

// kubernames_add function

function checkSelectItems(name) {
  // var oldname = GetQueryString("name");
  var oldname = name;
  if (oldname != null) {
    var storage = window.localStorage;
    var a1 = storage.kuberenvir;
    var lstobj = JSON.parse(a1);
    for (var i = 0; i < lstobj.Data.length; i++) {
      if (lstobj.Data[i].name == oldname) {
        lstobj.Data[i].name = $("#name").val()
      }
    }
    storage.kuberenvir = JSON.stringify(lstobj);
    timedloadenvir();
    // window.parent.window.loadmeun();
    // $.modalzClose();
    /*  $.ajax({
     type: "put",
     url: "/api/kubernamespace/edit/"+oldname+"/"+$("#name").val(),
     dataType: "json",
     success: function (res) {
     window.parent.window.dataload();
     window.parent.window.loadmeun();
     $.modalzClose();
     },
     error: function (res) {
     $.messageBox(res.responseText, "error");
     }
     })*/
  }
  else {
    var storage = window.localStorage;
    var a1 = storage.kuberenvir;
    var lstobj = JSON.parse(a1);
    var obj = new Object();
    obj.creationTimestamp = getNowFormatDate();
    obj.name = $("#name").val();
    obj.resourceVersion = Math.round(Math.random() * 1000);
    obj.status = "Active";
    obj.uid = generateMixed(8) + "-" + generateMixed(4) + "-" + generateMixed(4) + "-" + generateMixed(8);
    lstobj.Data.push(obj);
    storage.kuberenvir = JSON.stringify(lstobj);
    timedloadenvir();
    // window.parent.window.loadmeun();
    // $.modalzClose();
    // debugger
    /* $.ajax({
     type: "post",
     url: "/api/kubernamespace/add",
     dataType: "json",
     data: {"name": $("#name").val()},
     success: function (res) {
     window.parent.window.dataload();
     window.parent.window.loadmeun();
     $.modalzClose();
     },
     error: function (res) {
     $.messageBox(res.responseText, "error");
     }
     })*/
  }
}

// function GetQueryString(name) {
//   var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
//   var r = window.location.search.substr(1).match(reg);
//   if (r != null)return unescape(r[2]);
//   return null;
// }
function generateMixed(n) {
  var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'c', 'd', 'e', 'b', 'f'];
  var res = "";
  for (var i = 0; i < n; i++) {
    var id = Math.ceil(Math.random() * 15);
    res += chars[id];
  }
  return res;
}
function getNowFormatDate() {
  var date = new Date();
  var seperator1 = "-";
  var seperator2 = ":";
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
    + " " + date.getHours() + seperator2 + date.getMinutes()
    + seperator2 + date.getSeconds();
  return currentdate;
}

//数据展示页面创建数据
function dataShow_getProject() {
  var productList = JSON.parse(localStorage.getItem("productList"));
  if (productList === undefined || productList === null || productList.length < 1) {
    return;
  }
  // var productList = [{productKey:"ETL"},{productKey:"CD"},{productKey:"PDM"}];
  var project_data = {
    code: 200,
    errorMsg: "成功"
  };
  var results = [];
  for (var i = 0; i < productList.length; i++) {
    var result = new Object();
    result.description = "test" + i + 1;
    result.endDate = 1495900800000;
    result.id = i;
    result.personKeyAndRoles = {
      BM: ["simayangyang"],
      DE: ["yuxin", "wangyulei"],
      PM: ["wangyuanyuan"],
      TM: ["lichaochao", "liaoguangxian"]
    };
    result.productKeys = [productList[i].productName];
    result.projectName = productList[i].productName;
    result.startDate = 1493568000000;
    results.push(result);
  }
  project_data.result = results;

  localStorage.setItem("dataShow_project", JSON.stringify(project_data));
}

function dataShow_getRequirement(productKey) {
  // localStorage.setItem("dataShow_RequirementList",null);
  var requirement_dataMap = JSON.parse(localStorage.getItem("dataShow_RequirementList"));
  if (requirement_dataMap != undefined) {
    for (key in requirement_dataMap) {
      if (requirement_dataMap[key].productKey == productKey) {
        localStorage.setItem("dataShow_Requirement", JSON.stringify(requirement_dataMap[key]));
        return;
      }
    }
  } else {
    requirement_dataMap = {};
  }
  var latestrequirementsInfos = [
    {
      creationDate: 1488954507000,
      id: "5907e720de084a14541a1a90",
      level: "Major",
      personKey: "wangmiaoqiong",
      personName: "王妙琼",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-1087",
      productStatus: "Open",
      productTitle: "新增登录超时功能",
      productType: "新特性",
      updateDate: 1488954507000
    },
    {
      creationDate: 1488936602000,
      id: "5907e720de084a14541a1a92",
      level: "Major",
      personKey: "luochuan",
      personName: "罗川",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-1085",
      productStatus: "Open",
      productTitle: "内蒙项目中，开发storm到spark streaming程序执行agent",
      productType: "新特性",
      updateDate: 1488937038000
    },
    {
      creationDate: 1487228291000,
      id: "5907e720de084a14541a1ab3",
      level: "Major",
      personKey: "chenxi",
      personName: "陈曦 ",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-1052",
      productStatus: "Open",
      productTitle: "测试比较storm,spark streaming,flink等计算引擎吞吐量",
      productType: "任务",
      updateDate: 1487924035000
    },
    {
      creationDate: 1484551539000,
      id: "5907e720de084a14541a1b64",
      level: "Major",
      personKey: "chenxi",
      personName: "陈曦 ",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-875",
      productStatus: "Open",
      productTitle: "邮件内容如下",
      productType: "新特性",
      updateDate: 1484551539000
    },
    {
      creationDate: 1484551382000,
      id: "5907e720de084a14541a1b65",
      level: "Major",
      personKey: "fuhuaiyong",
      personName: "付怀勇",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-874",
      productStatus: "Open",
      productTitle: "目前我们的调度源有",
      productType: "新特性",
      updateDate: 1492415312000
    },
    {
      creationDate: 1484017576000,
      id: "5907e720de084a14541a1b66",
      level: "Major",
      personKey: "chenxi",
      personName: "陈曦 ",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-873",
      productStatus: "Open",
      productTitle: "监控视图中拓扑下方的拓扑监控信息增加metrics页面超链接，超链接加在拓扑名称上，点击拓扑名进入原metrics页面，如附件图",
      productType: "新特性",
      updateDate: 1484017576000
    },
    {
      creationDate: 1480326511000,
      id: "5907e720de084a14541a1be6",
      level: "Major",
      personKey: "chenxi",
      personName: "陈曦 ",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-745",
      productStatus: "Open",
      productTitle: "过滤组件优化，让用户输入过滤条件，如a>xxx and （c >xxxx or  b<=fwofmwofw）",
      productType: "新特性",
      updateDate: 1480326511000
    },
    {
      creationDate: 1476884470000,
      id: "5907e720de084a14541a1c4c",
      level: "Major",
      personKey: "chenxi",
      personName: "陈曦 ",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-643",
      productStatus: "Open",
      productTitle: "内蒙项目中加入hive输出组件",
      productType: "新特性",
      updateDate: 1476884470000
    },
    {
      creationDate: 1476007827000,
      id: "5907e720de084a14541a1c68",
      level: "Major",
      personKey: "chenxixi",
      personName: "陈曦曦 ",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-615",
      productStatus: "Open",
      productTitle: "1、调度支持把数据通过http请求的方式发送出去，需要配置",
      productType: "新特性",
      updateDate: 1476007827000
    },
    {
      creationDate: 1472458665000,
      id: "5907e720de084a14541a1cb4",
      level: "Major",
      personKey: "chenxi",
      personName: "陈曦 ",
      productKey: "STREAMING",
      productName: "流计算",
      productNumber: "STREAMING-539",
      productStatus: "Open",
      productTitle: "安装swagger ui",
      productType: "任务",
      updateDate: 1472458665000
    }
  ];
  latestrequirementsInfos.sort(randomSort);
  result = new Object();
  result.doingCount = Math.floor(Math.random() * 300);
  result.doneCount = Math.floor(Math.random() * 300);
  result.todoCount = Math.floor(Math.random() * 300);
  result.totalCount = result.doingCount + result.doneCount + result.todoCount;
  result.latestrequirementsInfo = latestrequirementsInfos

  var requirement_data = {
    code: 200,
    errorMsg: "成功",
    productKey: productKey

  };
  requirement_data.result = result;
  requirement_dataMap[productKey] = requirement_data;
  localStorage.setItem("dataShow_RequirementList", JSON.stringify(requirement_dataMap));
  localStorage.setItem("dataShow_Requirement", JSON.stringify(requirement_data));
}

function dataShow_xfgc(productKey) {
  // localStorage.setItem("dataShow_yfgcMap",null);
  var dataShow_yfgcMap = JSON.parse(localStorage.getItem("dataShow_yfgcMap"));
  if (dataShow_yfgcMap != undefined) {
    for (key in dataShow_yfgcMap) {
      if (dataShow_yfgcMap[key].productKey == productKey) {
        localStorage.setItem("dataShow_yfgc", JSON.stringify(dataShow_yfgcMap[key]));
        return;
      }
    }
  } else {
    dataShow_yfgcMap = {};
  }
  var compileInfoList = [];
  for (var i = 1; i < 31; i++) {
    var compileInfo = new Object();
    compileInfo.compileFailNum = Math.floor(Math.random() * 50 + 10);
    compileInfo.compileNum = Math.floor(Math.random() * 5 + 1);

    compileInfo.highData = Math.floor(Math.random() * 10 + 1);
    compileInfo.mediumData = Math.floor(Math.random() * 100 + 101);
    compileInfo.bugData = Math.floor(Math.random() * 10 + 201);

    compileInfo.conditionalNum = Math.floor(Math.random() * 99 + 1);
    compileInfo.methodNum = Math.floor(Math.random() * (100 - compileInfo.conditionalNum));
    compileInfo.statementNum = 100 - compileInfo.conditionalNum - compileInfo.methodNum;
    compileInfo.month = i + "日";
    compileInfoList.push(compileInfo);
  }
  var xfgc_data = {
    code: 200,
    errorMsg: "成功",
    productKey: productKey,
    result: {
      averageCoverRate: 10,
      compileSuccessRate: 20,
      totalCompileCount: 30
    }
  }
  xfgc_data["result"]["compileInfoList"] = compileInfoList;
  dataShow_yfgcMap[productKey] = xfgc_data;
  localStorage.setItem("dataShow_yfgc", JSON.stringify(xfgc_data));
  localStorage.setItem("dataShow_yfgcMap", JSON.stringify(dataShow_yfgcMap));
}

function dataShow_dmzl(productKey) {
  // localStorage.setItem("dataShow_dmzlMap",null);
  var dataShow_dmzlMap = JSON.parse(localStorage.getItem("dataShow_dmzlMap"));
  if (dataShow_dmzlMap != undefined) {
    for (key in dataShow_dmzlMap) {
      if (dataShow_dmzlMap[key].productKey == productKey) {
        localStorage.setItem("dataShow_dmzl", JSON.stringify(dataShow_dmzlMap[key]));
        return;
      }
    }
  } else {
    dataShow_dmzlMap = {};
  }
  var dmzl_data = {
    code: 200,
    errorMsg: "成功",
    productKey: productKey
  }
  var codeSubmitionList = [];
  var result = {};
  var total = 0;
  for (var i = 1; i < 31; i++) {
    var codeSubmition = new Object();
    codeSubmition.codeSubmitNum = Math.floor(Math.random() * 500 + 101);
    codeSubmition.month = i + "日";
    codeSubmitionList.push(codeSubmition);
    total = total + codeSubmition.codeSubmitNum;
  }
  result["codeSubmitionList"] = codeSubmitionList;
  result["totalCodeNum"] = total;
  dmzl_data["result"] = result;
  dataShow_dmzlMap[productKey] = dmzl_data;
  localStorage.setItem("dataShow_dmzl", JSON.stringify(dmzl_data));
  localStorage.setItem("dataShow_dmzlMap", JSON.stringify(dataShow_dmzlMap));
}

function dataShow_zxce(productKey) {
  // localStorage.setItem("dataShow_zxcsMap",null);
  var dataShow_zxcsMap = JSON.parse(localStorage.getItem("dataShow_zxcsMap"));
  if (dataShow_zxcsMap != undefined) {
    for (key in dataShow_zxcsMap) {
      if (dataShow_zxcsMap[key].productKey == productKey) {
        localStorage.setItem("dataShow_zxcs", JSON.stringify(dataShow_zxcsMap[key]));
        return;
      }
    }
  } else {
    dataShow_zxcsMap = {};
  }

  var zxcs_data = {
    code: 200,
    errorMsg: "成功",
    productKey: productKey
  }
  var result = {};
  result.finishedBugNum = 0;
  result.increaseBugNum = 0;
  result.processingBugNum = Math.floor(Math.random() * 900 + 1);
  result.reopenedBugNum = 0;
  result.unfinishBugNum = Math.floor(Math.random() * 900 + 1);
  var doneTestCaseANDJIRANumList = [];
  for (var i = 1; i < 31; i++) {
    var doneTestCaseANDJIRANum = {};
    doneTestCaseANDJIRANum.doneTestCaseNum = Math.floor(Math.random() * 30 + 1);
    doneTestCaseANDJIRANum.increaseJIRANum = Math.floor(Math.random() * 30 + 1);
    doneTestCaseANDJIRANum.openJIRANum = Math.floor(Math.random() * 30 + 1);
    doneTestCaseANDJIRANum.reopenJIRANum = Math.floor(Math.random() * 30 + 1);
    doneTestCaseANDJIRANum.closeJIRANum = Math.floor(Math.random() * 30 + 1);
    doneTestCaseANDJIRANum.month = i + "日";
    result.finishedBugNum = result.finishedBugNum + doneTestCaseANDJIRANum.closeJIRANum;
    result.increaseBugNum = result.increaseBugNum + doneTestCaseANDJIRANum.increaseJIRANum;
    result.reopenedBugNum = result.reopenedBugNum + doneTestCaseANDJIRANum.reopenJIRANum;
    doneTestCaseANDJIRANumList.push(doneTestCaseANDJIRANum);
  }
  result.doneTestCaseANDJIRANumList = doneTestCaseANDJIRANumList;
  zxcs_data.result = result;
  dataShow_zxcsMap[productKey] = zxcs_data;
  localStorage.setItem("dataShow_zxcs", JSON.stringify(zxcs_data));
  localStorage.setItem("dataShow_zxcsMap", JSON.stringify(dataShow_zxcsMap));
}
//乱序
function randomSort(a, b) {
  return Math.random() > 0.5 ? -1 : 1;
}
